package com.matt.service.estimate.impl;

import com.matt.domain.estimate.LikedRecord;
import com.matt.repository.estimate.LikedRecordRepository;
import com.matt.service.estimate.LikedRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Objects;

@Service
public class LikedRecordServiceImpl implements LikedRecordService {

    @Autowired
    private LikedRecordRepository likedRecordRepository;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public LikedRecord likeOrCancel(String courseId, String evaluatorId, String like) {
        // 点赞
//        if (Objects.equals(like, "false")) {
//            // 取消点赞
////            redisTemplate.opsForHash().increment(1, courseId, -1);
//            Integer integer = likedRecordRepository.deleteLikedRecordByUserIdAndBizId(evaluatorId, courseId);
//            LikedRecord likedRecord = new LikedRecord();
//            likedRecord.setId(String.valueOf());
//            return new LikedRecord();
//        }

//        redisTemplate.opsForHash().increment(1, courseId, 1);
        LikedRecord likedRecord = likedRecordRepository.addLikedRecord(evaluatorId,
                courseId, "1", String.valueOf(LocalDate.now()));

        return likedRecord;
    }
}
